package com.djq.hhc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.djq.hhc.mapper.HomeFlowerMapper;
import com.djq.hhc.model.home.HomeFamily;
import com.djq.hhc.model.home.HomeFlower;
import com.djq.hhc.result.Result;
import com.djq.hhc.service.HomeFlowerService;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: dadd7
 * @Date: 2023/03/05/下午 4:54
 * @Description:
 */

@Service
public class HomeFlowerServiceImpl extends ServiceImpl<HomeFlowerMapper, HomeFlower> implements HomeFlowerService {
    @Override
    public Result updateFlowerById(HomeFlower homeFlower) {
        Long id = homeFlower.getId();
        String flowerName = homeFlower.getFlowerName();
        HomeFlower one = query().eq("flower_name", flowerName).ne("id", id).one();
        if (one == null) {
            updateById(homeFlower);
            return Result.ok().message("修改花朵成功");
        } else {
            return Result.fail().message("花朵名字已存在");
        }
    }

    @Override
    public Result saveFlower(HomeFlower homeFlower) {
        String flowerName = homeFlower.getFlowerName();
        HomeFlower one = query().eq("flower_name", flowerName).one();
        if (one == null) {
            save(homeFlower);
            return Result.ok().message("添加花朵成功");
        } else {
            return Result.fail().message("花朵名字已存在");
        }
    }
}
